package com.bjqh.edu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bjqh.edu.Base.AppConstants;
import com.bjqh.edu.Bean.Teacher;
import com.bjqh.edu.R;
import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/9/13.
 */

public class MyTeacherAdapter extends BaseAdapter {

    private List<Teacher.DataBean> list;
    private Context ctx;
    private ViewHolder holder;

    public MyTeacherAdapter(Context ctx, List<Teacher.DataBean> data) {
        this.ctx = ctx;
        this.list = data;

    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {

        if (view == null) {
            view = LayoutInflater.from(ctx).inflate(R.layout.item_teacher_my, null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        if (list.get(position).getName() != null) {
            holder.tvTeacher.setText("姓名：" + list.get(position).getName());
        }
        if (list.get(position).getIntro() != null) {
            holder.tvJj.setText("简介：" + list.get(position).getIntro());
        }
        if (list.get(position).getRname() != null) {
            holder.tvKc.setText("课程：" + list.get(position).getRname());
        }
        Glide.with(ctx)
                .load(AppConstants.IMG_URL + list.get(position).getHeader())
                .asBitmap()
                .placeholder(R.mipmap.iv_err)
                .into(holder.ivHeader);
        return view;
    }


    static class ViewHolder {
        @BindView(R.id.tv_teacher)
        TextView tvTeacher;
        @BindView(R.id.tv_jj)
        TextView tvJj;
        @BindView(R.id.iv_header)
        ImageView ivHeader;
        @BindView(R.id.tv_kc)
        TextView tvKc;
        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

}
